/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JProductPrefPriceEditor.java
 *
 * Created on 2009-7-29, 12:31:46
 */

package com.openbravo.pos.inventory;

import cn.ekuma.data.ui.swing.AbstractDAOJEditor;
import cn.ekuma.epos.core.util.ProductSwingUtil;
import cn.ekuma.epos.datalogic.I_DataLogicSales;
import com.openbravo.data.basic.BasicException;
import com.openbravo.beans.JCalendarDialog;
import com.openbravo.data.gui.ComboBoxValEntry;
import com.openbravo.data.gui.ComboBoxValModel;
import com.openbravo.data.gui.MessageInf;
import com.openbravo.data.user.DirtyManager;
import com.openbravo.format.Formats;

import com.openbravo.pos.base.AppLocal;
import com.openbravo.pos.base.AppView;
import com.openbravo.bean.Product;
import com.openbravo.bean.ProductPrefPrice;
import com.openbravo.pos.panels.JProductAttEdit;
import com.openbravo.pos.panels.JProductFinder;
import java.awt.Component;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.util.Date;
import java.util.Properties;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.BoxLayout;
import javax.swing.border.TitledBorder;
import javax.swing.border.EtchedBorder;
import java.awt.Dimension;

/**
 * 
 * @author Administrator
 */
public class JProductPrefPriceEditor extends
		AbstractDAOJEditor<ProductPrefPrice> {
	private I_DataLogicSales m_dlSales;
	private Product product;
	private Product product1;
	private ComboBoxValModel prefTypeModel;
	private ComboBoxValModel prefModelTypemodel;
	AppView m_App;

	/** Creates new form JProductPrefPriceEditor */
	public JProductPrefPriceEditor(I_DataLogicSales dlSales,
			DirtyManager dirty, AppView app) {
		super(dirty);
		setPreferredSize(new Dimension(500, 470));
		initComponents();
		m_dlSales = dlSales;
		m_App = app;

		prefTypeModel = new ComboBoxValModel();
		prefTypeModel.add(new ComboBoxValEntry(
				ProductPrefPrice.PREFTYPE_QuotaPref, AppLocal
						.getIntString("list.preftype_quotapref")));
		prefTypeModel.add(new ComboBoxValEntry(
				ProductPrefPrice.PREFTYPE_OverPref, AppLocal
						.getIntString("list.preftype_overpref")));
		prefTypeModel.add(new ComboBoxValEntry(
				ProductPrefPrice.PREFTYPE_TimeAndQuotaPref, AppLocal
						.getIntString("list.preftype_timeandquotapref")));
		prefTypeModel.add(new ComboBoxValEntry(
				ProductPrefPrice.PREFTYPE_TimeAndOverPref, AppLocal
						.getIntString("list.preftype_timeandoverpref")));
		prefTypeModel.add(new ComboBoxValEntry(
				ProductPrefPrice.PREFTYPE_TimePref, AppLocal
						.getIntString("list.preftype_timepref")));

		prefModelTypemodel = new ComboBoxValModel();
		prefModelTypemodel.add(new ComboBoxValEntry(
				ProductPrefPrice.PREFMODETYPE_SellPrice, AppLocal
						.getIntString("list.prefmodetype_sellprice")));
		prefModelTypemodel.add(new ComboBoxValEntry(
				ProductPrefPrice.PREFMODETYPE_Rate, AppLocal
						.getIntString("list.prefmodetype_rate")));
		prefModelTypemodel.add(new ComboBoxValEntry(
				ProductPrefPrice.PREFMODETYPE_Largess, AppLocal
						.getIntString("list.prefmodetype_largess")));
		prefModelTypemodel.add(new ComboBoxValEntry(
				ProductPrefPrice.PREFMODETYPE_ImmeLargess, AppLocal
						.getIntString("list.prefmodetype_immelargess")));
		
		jPrefType.setModel(prefTypeModel);
		jprefModeType.setModel(prefModelTypemodel);
		
		jCustomerOnly.addActionListener(dirty);
		jStoreNum.getDocument().addDocumentListener(dirty);
		jselledNum.getDocument().addDocumentListener(dirty);
		jminNum.getDocument().addDocumentListener(dirty);
		jm_dStartDate.getDocument().addDocumentListener(dirty);
		jm_dStopDate.getDocument().addDocumentListener(dirty);
		jprefRate.getDocument().addDocumentListener(dirty);
		jprefPrice.getDocument().addDocumentListener(dirty);
		jLargessNum.getDocument().addDocumentListener(dirty);
		prodpricebuy.getDocument().addDocumentListener(dirty);
		jPrefType.addActionListener(dirty);
		jprefModeType.addActionListener(dirty);
	}

	private void vierfyPrefType() {
		jStoreNum.setEnabled(false);
		jselledNum.setEnabled(false);
		jminNum.setEnabled(false);
		jm_dStartDate.setEnabled(false);
		jm_dStopDate.setEnabled(false);
		m_jbtndate.setEnabled(false);
		m_jbtndate1.setEnabled(false);
		if (!jPrefType.isEnabled())
			return;
		ComboBoxValEntry prefType = (ComboBoxValEntry) jPrefType
				.getSelectedItem();
		if (ProductPrefPrice.PREFTYPE_OverPref
				.equalsIgnoreCase((String) prefType.getM_sKey())) {
			jminNum.setEnabled(true);
		} else if (ProductPrefPrice.PREFTYPE_QuotaPref
				.equalsIgnoreCase((String) prefType.getM_sKey())) {
			jStoreNum.setEnabled(true);
		} else if (ProductPrefPrice.PREFTYPE_TimeAndOverPref
				.equalsIgnoreCase((String) prefType.getM_sKey())) {
			jminNum.setEnabled(true);
			jm_dStartDate.setEnabled(true);
			jm_dStopDate.setEnabled(true);
			m_jbtndate.setEnabled(true);
			m_jbtndate1.setEnabled(true);
		} else if (ProductPrefPrice.PREFTYPE_TimeAndQuotaPref
				.equalsIgnoreCase((String) prefType.getM_sKey())) {
			jStoreNum.setEnabled(true);
			jm_dStartDate.setEnabled(true);
			jm_dStopDate.setEnabled(true);
			m_jbtndate.setEnabled(true);
			m_jbtndate1.setEnabled(true);
		} else if (ProductPrefPrice.PREFTYPE_TimePref
				.equalsIgnoreCase((String) prefType.getM_sKey())) {
			jm_dStartDate.setEnabled(true);
			jm_dStopDate.setEnabled(true);
			m_jbtndate.setEnabled(true);
			m_jbtndate1.setEnabled(true);
		}
	}

	private void vierfyPrefModeType() {
		jprefPrice.setEnabled(false);
		jprefRate.setEnabled(false);

		jproduct1.setEnabled(false);
		jEditProduct1.setEnabled(false);
		jattributes1.setEnabled(false);
		jEditAttributes1.setEnabled(false);
		jLargessNum.setEnabled(false);

		if (!jprefModeType.isEnabled())
			return;
		ComboBoxValEntry prefType = (ComboBoxValEntry) jprefModeType
				.getSelectedItem();
		if (ProductPrefPrice.PREFMODETYPE_Rate
				.equalsIgnoreCase((String) prefType.getM_sKey())) {
			jprefRate.setEnabled(true);
		} else if (ProductPrefPrice.PREFMODETYPE_SellPrice
				.equalsIgnoreCase((String) prefType.getM_sKey())) {
			jprefPrice.setEnabled(true);
		} else if (ProductPrefPrice.PREFMODETYPE_Largess
				.equalsIgnoreCase((String) prefType.getM_sKey())) {
			jproduct1.setEnabled(true);
			jEditProduct1.setEnabled(true);
			jattributes1.setEnabled(true);
			jEditAttributes1.setEnabled(true);
			jLargessNum.setEnabled(true);
		} else if (ProductPrefPrice.PREFMODETYPE_ImmeLargess
				.equalsIgnoreCase((String) prefType.getM_sKey())) {
		}
	}

	@Override
	public void refresh() {
	}

	@Override
	public Component getComponent() {
		return this;
	}

	private void assignProductByReference() {
		try {
			Product prod = m_dlSales.getProductInfoByReference(m_jreference
					.getText());
			if (prod == null) {
				Toolkit.getDefaultToolkit().beep();
			}
			assignProduct(prod);
		} catch (BasicException eData) {
			MessageInf msg = new MessageInf(eData);
			msg.show(this);
			assignProduct(null);
		}
	}

	private void assignProductByCode() {
			Product prod =ProductSwingUtil.getProductInfo(this, m_dlSales, m_jcodebar.getText());
			if (prod == null) {
				Toolkit.getDefaultToolkit().beep();
			}
			assignProduct(prod);
	}

	private void assignProduct(Product prod) {
		product = prod;
		if (product == null) {
			jproduct.setText(null);
			m_jcodebar.setText(null);
			m_jreference.setText(null);
			jsellPrice.setText(null);
			jcustomerPrice.setText(null);
			baseProdpricebuy.setText(null);
		} else {
			jproduct.setText(product.getReference() + " - " + product.getName());
			m_jcodebar.setText(product.getCode());
			m_jreference.setText(product.getReference());
			jsellPrice.setText(Formats.CURRENCY.formatValue(product
					.getPriceSell()));
			jcustomerPrice.setText(Formats.CURRENCY.formatValue(product
					.getM_dCustomerPrice()));
			baseProdpricebuy.setText(Formats.CURRENCY.formatValue(product.getPriceBuy()));
		}
		dirty.setDirty(true);
	}

	private void assignProduct1(Product prod) {
		product1 = prod;
		if (product1 == null) {
			jproduct1.setText(null);
			jattributes1.setText(null);
		} else {
			jproduct1.setText(product1.getReference() + " - "
					+ product1.getName());
			jattributes1.setText(null);
		}
		dirty.setDirty(true);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {
		
				jPanel1 = new javax.swing.JPanel();
				jPanel1.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
				jLabel3 = new javax.swing.JLabel();
				jLabel3.setBounds(10, 10, 150, 15);
				jLabel6 = new javax.swing.JLabel();
				jLabel6.setBounds(160, 10, 120, 15);
				m_jreference = new javax.swing.JTextField();
				m_jreference.setBounds(280, 10, 130, 21);
				m_jEnter1 = new javax.swing.JButton();
				m_jEnter1.setBounds(420, 10, 40, 24);
				m_jEnter = new javax.swing.JButton();
				m_jEnter.setBounds(420, 36, 40, 24);
				m_jcodebar = new javax.swing.JTextField();
				m_jcodebar.setBounds(280, 36, 130, 21);
				jLabel7 = new javax.swing.JLabel();
				jLabel7.setBounds(160, 36, 120, 15);
				jproduct = new javax.swing.JTextField();
				jproduct.setBounds(160, 66, 250, 21);
				jEditProduct = new javax.swing.JButton();
				jEditProduct.setBounds(420, 66, 40, 25);
				jLabel9 = new javax.swing.JLabel();
				jLabel9.setBounds(10, 92, 150, 15);
				jattributes = new javax.swing.JTextField();
				jattributes.setBounds(160, 92, 250, 21);
				jEditAttributes = new javax.swing.JButton();
				jEditAttributes.setBounds(420, 92, 40, 25);
				jPrefType = new javax.swing.JComboBox();
				jprefModeType = new javax.swing.JComboBox();
				panel = new JPanel();
				panel_1 = new JPanel();
				
						jLabel3.setText(AppLocal.getIntString("label.stockproduct")); // NOI18N
						
								jLabel6.setText(AppLocal.getIntString("label.prodref")); // NOI18N
								
										m_jreference.addActionListener(new java.awt.event.ActionListener() {
											public void actionPerformed(java.awt.event.ActionEvent evt) {
												m_jreferenceActionPerformed(evt);
											}
										});
										
												m_jEnter1.setIcon(new javax.swing.ImageIcon(getClass().getResource(
														"/com/openbravo/images/apply.png"))); // NOI18N
												m_jEnter1.setFocusPainted(false);
												m_jEnter1.setFocusable(false);
												m_jEnter1.setRequestFocusEnabled(false);
												m_jEnter1.addActionListener(new java.awt.event.ActionListener() {
													public void actionPerformed(java.awt.event.ActionEvent evt) {
														m_jEnter1ActionPerformed(evt);
													}
												});
												
														m_jEnter.setIcon(new javax.swing.ImageIcon(getClass().getResource(
																"/com/openbravo/images/apply.png"))); // NOI18N
														m_jEnter.setFocusPainted(false);
														m_jEnter.setFocusable(false);
														m_jEnter.setRequestFocusEnabled(false);
														m_jEnter.addActionListener(new java.awt.event.ActionListener() {
															public void actionPerformed(java.awt.event.ActionEvent evt) {
																m_jEnterActionPerformed(evt);
															}
														});
														
																m_jcodebar.addActionListener(new java.awt.event.ActionListener() {
																	public void actionPerformed(java.awt.event.ActionEvent evt) {
																		m_jcodebarActionPerformed(evt);
																	}
																});
																
																		jLabel7.setText(AppLocal.getIntString("label.prodbarcode")); // NOI18N
																		
																				jproduct.setEditable(false);
																				
																						jEditProduct.setIcon(new javax.swing.ImageIcon(getClass().getResource(
																								"/com/openbravo/images/search.png"))); // NOI18N
																						jEditProduct.addActionListener(new java.awt.event.ActionListener() {
																							public void actionPerformed(java.awt.event.ActionEvent evt) {
																								jEditProductActionPerformed(evt);
																							}
																						});
																						
																								jLabel9.setText(AppLocal.getIntString("label.attributes")); // NOI18N
																								
																										jattributes.setEditable(false);
																										
																												jEditAttributes.setIcon(new javax.swing.ImageIcon(getClass()
																														.getResource("/com/openbravo/images/colorize16.png"))); // NOI18N
																												jEditAttributes.setEnabled(false);
																												jEditAttributes.addActionListener(new java.awt.event.ActionListener() {
																													public void actionPerformed(java.awt.event.ActionEvent evt) {
																														jEditAttributesActionPerformed(evt);
																													}
																												});
																												
																												lblNewLabel = new JLabel(AppLocal.getIntString("label.prodpricebuy"));
																												lblNewLabel.setBounds(10, 127, 150, 15);
																												
																												prodpricebuy = new JTextField();
																												prodpricebuy.setBounds(160, 127, 92, 21);
																												prodpricebuy.setColumns(10);
																												
																												JLabel lblNewLabel_1 = new JLabel(AppLocal.getIntString("label.baseProdpricebuy"));
																												lblNewLabel_1.setBounds(281, 130, 102, 15);
																												
																												baseProdpricebuy = new JTextField();
																												baseProdpricebuy.setEditable(false);
																												baseProdpricebuy.setBounds(385, 127, 75, 21);
																												baseProdpricebuy.setColumns(10);
																												
																														add(jPanel1);
																														jPanel1.setLayout(null);
																														jPanel1.add(lblNewLabel);
																														jPanel1.add(prodpricebuy);
																														jPanel1.add(lblNewLabel_1);
																														jPanel1.add(baseProdpricebuy);
																														jPanel1.add(jLabel7);
																														jPanel1.add(m_jcodebar);
																														jPanel1.add(m_jEnter);
																														jPanel1.add(jLabel3);
																														jPanel1.add(jLabel6);
																														jPanel1.add(m_jreference);
																														jPanel1.add(m_jEnter1);
																														jPanel1.add(jproduct);
																														jPanel1.add(jEditProduct);
																														jPanel1.add(jLabel9);
																														jPanel1.add(jattributes);
																														jPanel1.add(jEditAttributes);
		
		
		
		panel_1.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		add(panel_1);
		panel_1.setLayout(null);
		jPrefTypeLabel = new javax.swing.JLabel();
		jPrefTypeLabel.setBounds(10, 9, 150, 21);
		panel_1.add(jPrefTypeLabel);
		
				jPrefTypeLabel.setText(AppLocal.getIntString("label.preftype"));
				jStoreNumLabel = new javax.swing.JLabel();
				jStoreNumLabel.setBounds(10, 39, 150, 21);
				panel_1.add(jStoreNumLabel);
				
						jStoreNumLabel.setText(AppLocal.getIntString("label.storeNum"));
						jminNumLabel = new javax.swing.JLabel();
						jminNumLabel.setBounds(10, 69, 150, 21);
						panel_1.add(jminNumLabel);
						
								jminNumLabel.setText(AppLocal.getIntString("label.minNum"));
								jm_dStartDateLabel = new javax.swing.JLabel();
								jm_dStartDateLabel.setBounds(10, 99, 150, 21);
								panel_1.add(jm_dStartDateLabel);
								
										jm_dStartDateLabel.setText(AppLocal.getIntString("label.m_dStartDate"));
										jm_dStopDateLabel = new javax.swing.JLabel();
										jm_dStopDateLabel.setBounds(10, 129, 150, 15);
										panel_1.add(jm_dStopDateLabel);
										
												jm_dStopDateLabel.setText(AppLocal.getIntString("label.m_dStopDate"));

												jPrefType.addActionListener(new java.awt.event.ActionListener() {
													@Override
													public void actionPerformed(ActionEvent e) {
														vierfyPrefType();
													}
												});
												
												jPrefType.setBounds(156, 9, 134, 21);
												panel_1.add(jPrefType);
												
												jStoreNum = new javax.swing.JTextField();
												jStoreNum.setBounds(156, 38, 134, 21);
												panel_1.add(jStoreNum);
												
														jStoreNum.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
														jselledNumLabel = new javax.swing.JLabel();
														jselledNumLabel.setBounds(300, 42, 77, 15);
														panel_1.add(jselledNumLabel);
														
																jselledNumLabel.setText(AppLocal.getIntString("label.selledNum"));
																jselledNum = new javax.swing.JTextField();
																jselledNum.setBounds(375, 39, 82, 21);
																panel_1.add(jselledNum);
																
																		jselledNum.setEditable(false);
																		jselledNum.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
																		
																				
																				jCustomerOnly = new javax.swing.JRadioButton();
																				jCustomerOnly.setBounds(365, 6, 105, 23);
																				panel_1.add(jCustomerOnly);
																				
																						jCustomerOnly.setText(AppLocal.getIntString("label.customer")); // NOI18N
																						jCustomerOnly.setEnabled(false);
																						
																						jminNum = new javax.swing.JTextField();
																						jminNum.setBounds(156, 67, 134, 21);
																						panel_1.add(jminNum);
																						
																								jminNum.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
																								
																								jm_dStopDate = new javax.swing.JTextField();
																								jm_dStopDate.setBounds(156, 125, 247, 21);
																								panel_1.add(jm_dStopDate);

																								jm_dStartDate = new javax.swing.JTextField();
																								jm_dStartDate.setBounds(156, 96, 247, 21);
																								panel_1.add(jm_dStartDate);
																								m_jbtndate = new javax.swing.JButton();
																								m_jbtndate.setBounds(417, 129, 40, 25);
																								panel_1.add(m_jbtndate);
																								
																										m_jbtndate.setIcon(new javax.swing.ImageIcon(getClass().getResource(
																												"/com/openbravo/images/date.png"))); // NOI18N
																										m_jbtndate1 = new javax.swing.JButton();
																										m_jbtndate1.setBounds(417, 99, 40, 25);
																										panel_1.add(m_jbtndate1);
																										
																												m_jbtndate1.setIcon(new javax.swing.ImageIcon(getClass().getResource(
																														"/com/openbravo/images/date.png"))); // NOI18N
																												m_jbtndate1.addActionListener(new java.awt.event.ActionListener() {
																													public void actionPerformed(java.awt.event.ActionEvent evt) {
																														m_jbtndate1ActionPerformed(evt);
																													}
																												});
																												m_jbtndate.addActionListener(new java.awt.event.ActionListener() {
																													public void actionPerformed(java.awt.event.ActionEvent evt) {
																														m_jbtndateActionPerformed(evt);
																													}
																												});
		
		
		panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		add(panel);
		panel.setLayout(null);
		jLabel4 = new javax.swing.JLabel();
		jLabel4.setBounds(10, 91, 150, 15);
		panel.add(jLabel4);
		
				jLabel4.setText(AppLocal.getIntString("label.stockproduct"));
				jLabel11 = new javax.swing.JLabel();
				jLabel11.setBounds(10, 116, 150, 15);
				panel.add(jLabel11);
				
						jLabel11.setText(AppLocal.getIntString("label.attributes"));
						jprefPriceLabel = new javax.swing.JLabel();
						jprefPriceLabel.setBounds(10, 66, 150, 15);
						panel.add(jprefPriceLabel);
						
								jprefPriceLabel.setText(AppLocal.getIntString("label.prefPrice"));
								jprefModeTypeLabel = new javax.swing.JLabel();
								jprefModeTypeLabel.setBounds(10, 10, 150, 15);
								panel.add(jprefModeTypeLabel);
								
										jprefModeTypeLabel.setText(AppLocal.getIntString("label.prefModeType"));
										jprefRateLabel = new javax.swing.JLabel();
										jprefRateLabel.setBounds(10, 41, 150, 15);
										panel.add(jprefRateLabel);
										
												jprefRateLabel.setText(AppLocal.getIntString("label.prefRate"));
												jattributes1 = new javax.swing.JTextField();
												jattributes1.setBounds(158, 116, 127, 21);
												panel.add(jattributes1);
												
														jattributes1.setEditable(false);
														jEditAttributes1 = new javax.swing.JButton();
														jEditAttributes1.setBounds(294, 112, 49, 25);
														panel.add(jEditAttributes1);
														
																jEditAttributes1.setIcon(new javax.swing.ImageIcon(getClass()
																		.getResource("/com/openbravo/images/colorize16.png"))); // NOI18N
																jLargessNumLabel = new javax.swing.JLabel();
																jLargessNumLabel.setBounds(349, 116, 36, 15);
																panel.add(jLargessNumLabel);
																
																		jLargessNumLabel.setText(AppLocal.getIntString("label.LargessNum"));
																		jproduct1 = new javax.swing.JTextField();
																		jproduct1.setBounds(158, 91, 227, 21);
																		panel.add(jproduct1);
																		
																				jproduct1.setEditable(false);
																				
																				jLargessNum = new javax.swing.JTextField();
																				jLargessNum.setBounds(405, 113, 57, 21);
																				panel.add(jLargessNum);
																				
																						jLargessNum.setHorizontalAlignment(javax.swing.JTextField.LEFT);
																						
																						jprefPrice = new javax.swing.JTextField();
																						jprefPrice.setBounds(158, 66, 125, 21);
																						panel.add(jprefPrice);
																						
																								jprefPrice.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
																								jcustomerPriceLabel = new javax.swing.JLabel();
																								jcustomerPriceLabel.setBounds(307, 54, 36, 15);
																								panel.add(jcustomerPriceLabel);
																								
																										jcustomerPriceLabel.setText(AppLocal
																												.getIntString("label.baseCustomerPrice"));
																										jsellPriceLabel = new javax.swing.JLabel();
																										jsellPriceLabel.setBounds(307, 29, 36, 15);
																										panel.add(jsellPriceLabel);
																										
																												jsellPriceLabel.setText(AppLocal.getIntString("label.basePrice"));
																												jsellPrice = new javax.swing.JTextField();
																												jsellPrice.setBounds(364, 26, 77, 21);
																												panel.add(jsellPrice);
																												
																														jsellPrice.setEditable(false);
																														jsellPrice.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
																														jcustomerPrice = new javax.swing.JTextField();
																														jcustomerPrice.setBounds(363, 51, 77, 21);
																														panel.add(jcustomerPrice);
																														
																																jcustomerPrice.setEditable(false);
																																jcustomerPrice.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
																																jprefModeType.addActionListener(new java.awt.event.ActionListener() {
																																	@Override
																																	public void actionPerformed(ActionEvent e) {
																																		vierfyPrefModeType();
																																	}
																																});
																																
																																
																																jprefModeType.setBounds(158, 10, 125, 21);
																																panel.add(jprefModeType);
																																
																																jprefRate = new javax.swing.JTextField();
																																jprefRate.setBounds(158, 41, 125, 21);
																																panel.add(jprefRate);
																																
																																		jprefRate.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
																																		jEditProduct1 = new javax.swing.JButton();
																																		jEditProduct1.setBounds(395, 81, 40, 25);
																																		panel.add(jEditProduct1);
																																		
																																				jEditProduct1.setIcon(new javax.swing.ImageIcon(getClass().getResource(
																																						"/com/openbravo/images/search.png"))); // NOI18N
																																				jEditProduct1.addActionListener(new java.awt.event.ActionListener() {
																																					public void actionPerformed(java.awt.event.ActionEvent evt) {
																																						jEditProduct1ActionPerformed(evt);
																																					}
																																				});
																jEditAttributes1.addActionListener(new java.awt.event.ActionListener() {
																	public void actionPerformed(java.awt.event.ActionEvent evt) {
																		jEditAttributes1ActionPerformed(evt);
																	}
																});
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		
	}// </editor-fold>//GEN-END:initComponents

	private void m_jreferenceActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_m_jreferenceActionPerformed
		assignProductByReference();
	}// GEN-LAST:event_m_jreferenceActionPerformed

	private void m_jEnter1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_m_jEnter1ActionPerformed

		assignProductByReference();
	}// GEN-LAST:event_m_jEnter1ActionPerformed

	private void m_jEnterActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_m_jEnterActionPerformed

		assignProductByCode();
	}// GEN-LAST:event_m_jEnterActionPerformed

	private void m_jcodebarActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_m_jcodebarActionPerformed

		assignProductByCode();
	}// GEN-LAST:event_m_jcodebarActionPerformed

	private void jEditProductActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jEditProductActionPerformed

		assignProduct(JProductFinder.showMessage(this, m_dlSales));
	}// GEN-LAST:event_jEditProductActionPerformed

	private void jEditAttributesActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jEditAttributesActionPerformed

		if (product == null) {
			// first select the product.
			MessageInf msg = new MessageInf(MessageInf.SGN_WARNING,
					AppLocal.getIntString("message.productnotselected"));
			msg.show(this);
		} else {
			try {
				JProductAttEdit attedit = JProductAttEdit
						.getAttributesEditor(this, m_dlSales);
				attedit.editAttributes(product.getAttributeSetID(),
						jattributes.getText(), true);
				attedit.setVisible(true);
				if (attedit.isOK()) {
					// The user pressed OK
					jattributes.setText(attedit.getAttributeSetInstance().getId());
				}
			} catch (BasicException ex) {
				MessageInf msg = new MessageInf(MessageInf.SGN_WARNING,
						AppLocal.getIntString("message.cannotfindattributes"),
						ex);
				msg.show(this);
			}
		}
	}// GEN-LAST:event_jEditAttributesActionPerformed

	private void jEditProduct1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jEditProduct1ActionPerformed

		assignProduct1(JProductFinder.showMessage(this, m_dlSales));
	}// GEN-LAST:event_jEditProduct1ActionPerformed

	private void jEditAttributes1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jEditAttributes1ActionPerformed

		if (product1 == null) {
			// first select the product.
			MessageInf msg = new MessageInf(MessageInf.SGN_WARNING,
					AppLocal.getIntString("message.productnotselected"));
			msg.show(this);
		} else {
			try {
				JProductAttEdit attedit = JProductAttEdit
						.getAttributesEditor(this, m_dlSales);
				attedit.editAttributes(product1.getAttributeSetID(),
						jattributes1.getText(), true);
				attedit.setVisible(true);
				if (attedit.isOK()) {
					// The user pressed OK
					jattributes1.setText(attedit.getAttributeSetInstance().getId());
					
				}
			} catch (BasicException ex) {
				MessageInf msg = new MessageInf(MessageInf.SGN_WARNING,
						AppLocal.getIntString("message.cannotfindattributes"),
						ex);
				msg.show(this);
			}
		}
	}// GEN-LAST:event_jEditAttributes1ActionPerformed

	private void m_jbtndateActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_m_jbtndateActionPerformed

		Date date;
		try {
			date = (Date) Formats.TIMESTAMP.parseValue(jm_dStartDate.getText());
		} catch (BasicException e) {
			date = null;
		}
		date = JCalendarDialog.showCalendarTime(this, date);
		if (date != null) {
			jm_dStartDate.setText(Formats.TIMESTAMP.formatValue(date));
		}
	}// GEN-LAST:event_m_jbtndateActionPerformed

	private void m_jbtndate1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_m_jbtndate1ActionPerformed

		Date date;
		try {
			date = (Date) Formats.TIMESTAMP.parseValue(jm_dStopDate.getText());
		} catch (BasicException e) {
			date = null;
		}
		date = JCalendarDialog.showCalendarTime(this, date);
		if (date != null) {
			jm_dStopDate.setText(Formats.TIMESTAMP.formatValue(date));
		}
	}// GEN-LAST:event_m_jbtndate1ActionPerformed

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JRadioButton jCustomerOnly;
	private javax.swing.JButton jEditAttributes;
	private javax.swing.JButton jEditAttributes1;
	private javax.swing.JButton jEditProduct;
	private javax.swing.JButton jEditProduct1;
	private javax.swing.JLabel jLabel11;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel6;
	private javax.swing.JLabel jLabel7;
	private javax.swing.JLabel jLabel9;
	private javax.swing.JTextField jLargessNum;
	private javax.swing.JLabel jLargessNumLabel;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JComboBox jPrefType;
	private javax.swing.JLabel jPrefTypeLabel;
	private javax.swing.JTextField jStoreNum;
	private javax.swing.JLabel jStoreNumLabel;
	private javax.swing.JTextField jattributes;
	private javax.swing.JTextField jattributes1;
	private javax.swing.JTextField jcustomerPrice;
	private javax.swing.JLabel jcustomerPriceLabel;
	private javax.swing.JTextField jm_dStartDate;
	private javax.swing.JLabel jm_dStartDateLabel;
	private javax.swing.JTextField jm_dStopDate;
	private javax.swing.JLabel jm_dStopDateLabel;
	private javax.swing.JTextField jminNum;
	private javax.swing.JLabel jminNumLabel;
	private javax.swing.JComboBox jprefModeType;
	private javax.swing.JLabel jprefModeTypeLabel;
	private javax.swing.JTextField jprefPrice;
	private javax.swing.JLabel jprefPriceLabel;
	private javax.swing.JTextField jprefRate;
	private javax.swing.JLabel jprefRateLabel;
	private javax.swing.JTextField jproduct;
	private javax.swing.JTextField jproduct1;
	private javax.swing.JTextField jsellPrice;
	private javax.swing.JLabel jsellPriceLabel;
	private javax.swing.JTextField jselledNum;
	private javax.swing.JLabel jselledNumLabel;
	private javax.swing.JButton m_jEnter;
	private javax.swing.JButton m_jEnter1;
	private javax.swing.JButton m_jbtndate;
	private javax.swing.JButton m_jbtndate1;
	private javax.swing.JTextField m_jcodebar;
	private javax.swing.JTextField m_jreference;
	private JPanel panel;
	private JPanel panel_1;
	private JLabel lblNewLabel;
	private JTextField prodpricebuy;
	private JTextField baseProdpricebuy;

	// End of variables declaration//GEN-END:variables

	private final static Double readCurrency(String sValue) {
		try {
			return (Double) Formats.CURRENCY.parseValue(sValue);
		} catch (BasicException e) {
			return null;
		}
	}

	private final static Double readPercent(String sValue) {
		try {
			return (Double) Formats.PERCENT.parseValue(sValue);
		} catch (BasicException e) {
			return null;
		}
	}

	@Override
	public void activate() throws BasicException {

	}

	@Override
	public void updateUI(boolean editAble, int state) {

		if (obj.getM_sId() != null) {
			try {
				product = m_dlSales.getProductInfo(obj.getM_sId());
				assignProduct(product);
			} catch (BasicException ex) {
				MessageInf msg = new MessageInf(ex);
				msg.show(this);
				assignProduct(null);
			}
		} else
			assignProduct(null);
		prefTypeModel.setSelectedKey(obj.getPrefType());
		
		jStoreNum.setText(Formats.DOUBLE.formatValue(obj.getStoreNum()));
		jselledNum.setText(Formats.DOUBLE.formatValue(obj.getSelledNum()));
		jminNum.setText(Formats.DOUBLE.formatValue(obj.getMinNum()));
		jm_dStartDate.setText(Formats.TIMESTAMP.formatValue(obj
				.getM_dStartDate()));
		jm_dStopDate
				.setText(Formats.TIMESTAMP.formatValue(obj.getM_dStopDate()));

		prefModelTypemodel.setSelectedKey(obj.getPrefModeType());
		jprefPrice.setText(Formats.CURRENCY.formatValue(obj.getPrefPrice()));
		jprefRate.setText(Formats.DOUBLE.formatValue(obj.getPrefRate()));
        prodpricebuy.setText(Formats.DOUBLE.formatValue(obj.getPrefBuyPrice()));
		
		jattributes.setText(obj.getAttributesetid());
		if (obj.getM_sLargessId() != null) {
			try {
				product1 = m_dlSales.getProductInfo(obj.getM_sLargessId());
				assignProduct1(product1);
			} catch (BasicException ex) {
				MessageInf msg = new MessageInf(ex);
				msg.show(this);
				assignProduct1(null);
			}
		} else
			assignProduct1(null);
		jattributes1.setText(obj.getLargessAttributesetid());
		jLargessNum.setText(Formats.DOUBLE.formatValue(obj.getLargessNum()));

		m_jcodebar.setEnabled(editAble);
		m_jreference.setEnabled(editAble);
		m_jEnter.setEnabled(editAble);
		m_jEnter1.setEnabled(editAble);
		jproduct.setEnabled(editAble);
		jEditProduct.setEnabled(editAble);
		jattributes.setEnabled(editAble);
		jEditAttributes.setEnabled(editAble);

		jPrefType.setEnabled(editAble);
		jprefModeType.setEnabled(editAble);
		prodpricebuy.setEditable(editAble);

		vierfyPrefType();
		vierfyPrefModeType();

	}

	@Override
	public Class getEditClass() {
		return ProductPrefPrice.class;
	}

	@Override
	public void rebuild(ProductPrefPrice obj) throws BasicException {
		if (product == null) {
			// first select the product.
			MessageInf msg = new MessageInf(MessageInf.SGN_WARNING,
					AppLocal.getIntString("message.productnotselected"));
			msg.show(this);
			return;
		}
		obj.setM_sId(product.getID());
		obj.setP_name(product.getName());
		obj.setAttributesetid(jattributes.getText().isEmpty()?null:jattributes.getText());
		obj.setIsCustomerPref(jCustomerOnly.isSelected());
		obj.setPrefType((String) prefTypeModel.getSelectedKey());
		obj.setStoreNum((Double) Formats.DOUBLE.parseValue(jStoreNum.getText()));
		obj.setSelledNum((Double) Formats.DOUBLE.parseValue(jselledNum
				.getText()));
		obj.setMinNum((Double) Formats.DOUBLE.parseValue(jminNum.getText()));
		obj.setM_dStartDate((Date) Formats.TIMESTAMP.parseValue(jm_dStartDate
				.getText()));
		obj.setM_dStopDate((Date) Formats.TIMESTAMP.parseValue(jm_dStopDate
				.getText()));
		obj.setPrefModeType((String) prefModelTypemodel.getSelectedKey());
		obj.setPrefRate((Double) Formats.CURRENCY.parseValue(jprefRate
				.getText()));
		obj.setPrefPrice((Double) Formats.CURRENCY.parseValue(jprefPrice
				.getText()));
		obj.setM_sLargessId(product1 == null ? null : product1.getID());
		obj.setLargessAttributesetid(jattributes1.getText().isEmpty()?null:jattributes1.getText());
		obj.setLargessNum((Double) Formats.DOUBLE.parseValue(jLargessNum
				.getText()));
		obj.setPrefBuyPrice((Double) Formats.CURRENCY.parseValue(prodpricebuy.getText()));
	}

	@Override
	public ProductPrefPrice createNew(Properties prop) {

		return new ProductPrefPrice();
	}
}
